﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
using Assist;
using YArchitech.LIB;

namespace HYElectricSystemDiagram.DataStruct
{
	public class GetXmlData
	{
		private static XmlNode GetXmlNode(string dir = null)
		{
			string text;
			if (dir == null)
			{
				text = Path.Combine(Product.WorkingLocation, "SystemGraphSet.xml");
				if (!File.Exists(text))
				{
					string text2 = "SystemGraphSet.xml";
					string sourceFileName = AssistFunc.GetAppRootPath() + "\\Data\\ElectricalData\\" + text2;
					string destFileName = Product.WorkingLocation + text2;
					File.Copy(sourceFileName, destFileName);
				}
			}
			else
			{
				text = dir;
			}
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(text);
			if ((xmlDocument.FirstChild.NextSibling as XmlElement).GetAttribute("version") != "BIMSpace2019")
			{
				string text3 = "SystemGraphSet.xml";
				string sourceFileName2 = AssistFunc.GetAppRootPath() + "\\Data\\ElectricalData\\" + text3;
				string text4 = Product.WorkingLocation + text3;
				File.Delete(text4);
				File.Copy(sourceFileName2, text4);
			}
			XmlNode documentElement = xmlDocument.DocumentElement;
			GetXmlData.sxmlDoc = xmlDocument;
			GetXmlData.strDirXml = text;
			return documentElement;
		}

		public static int GetSetViewType(bool bl, int index = 0)
		{
			int result = 0;
			XmlNode xmlNode = GetXmlData.GetXmlNode(null);
			int i = 0;
			while (i < xmlNode.ChildNodes.Count)
			{
				XmlNode xmlNode2 = xmlNode.ChildNodes[i];
				if (xmlNode2.Name == "SystemGramViewType")
				{
					if (bl)
					{
						result = xmlNode2.Attributes["Index"].Value.ToInt(0);
						break;
					}
					((XmlElement)xmlNode2).SetAttribute("Index", index.ToString());
					GetXmlData.sxmlDoc.Save(GetXmlData.strDirXml);
					break;
				}
				else
				{
					i++;
				}
			}
			return result;
		}

		public static Dictionary<string, List<string>> GetLstLstSetInfo1()
		{
			Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();
			XmlNode xmlNode = GetXmlData.GetXmlNode(null);
			for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
			{
				XmlNode xmlNode2 = xmlNode.ChildNodes[i];
				if (xmlNode2.Name == "UserControlData1")
				{
					for (int j = 0; j < xmlNode2.ChildNodes.Count; j++)
					{
						XmlNode xmlNode3 = xmlNode2.ChildNodes[j];
						if (xmlNode3.Name == "FanBoxSize" || xmlNode3.Name == "PumpBoxSize" || xmlNode3.Name == "FireFightingLineType" || xmlNode3.Name == "NormalLineType" || xmlNode3.Name == "SpoolType")
						{
							List<string> list = new List<string>();
							foreach (object obj in xmlNode3.ChildNodes)
							{
								XmlNode xmlNode4 = (XmlNode)obj;
								list.Add(xmlNode4.Attributes["Attribute"].Value);
							}
							dictionary.Add(xmlNode3.Name, list);
						}
					}
				}
			}
			return dictionary;
		}

		public static Dictionary<string, string> GetNamSet()
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			XmlNode xmlNode = GetXmlData.GetXmlNode(null);
			for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
			{
				XmlNode xmlNode2 = xmlNode.ChildNodes[i];
				if (xmlNode2.Name == "UserControlData1")
				{
					for (int j = 0; j < xmlNode2.ChildNodes.Count; j++)
					{
						XmlNode xmlNode3 = xmlNode2.ChildNodes[j];
						if (xmlNode3.Name == "NameSet")
						{
							foreach (object obj in xmlNode3.ChildNodes)
							{
								XmlNode xmlNode4 = (XmlNode)obj;
								string value = xmlNode4.Attributes["Name"].Value;
								string value2 = xmlNode4.Attributes["Attribute"].Value;
								if (!dictionary.Keys.Contains(value2))
								{
									dictionary.Add(value2, value);
								}
							}
						}
					}
				}
			}
			return dictionary;
		}

		public static List<List<LineSettingIn>> GetLineSettingInInfo(string dir = null)
		{
			List<List<LineSettingIn>> list = new List<List<LineSettingIn>>();
			XmlNode xmlNode = GetXmlData.GetXmlNode(dir);
			for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
			{
				XmlNode xmlNode2 = xmlNode.ChildNodes[i];
				if (xmlNode2.Name == "UserControlData1")
				{
					for (int j = 0; j < xmlNode2.ChildNodes.Count; j++)
					{
						XmlNode xmlNode3 = xmlNode2.ChildNodes[j];
						if (xmlNode3.Name == "LineSettingIn")
						{
							foreach (object obj in xmlNode3.ChildNodes)
							{
								XmlNode xmlNode4 = (XmlNode)obj;
								List<LineSettingIn> list2 = new List<LineSettingIn>();
								foreach (object obj2 in xmlNode4.ChildNodes)
								{
									XmlNode xmlNode5 = (XmlNode)obj2;
									LineSettingIn lineSettingIn = new LineSettingIn();
									if (!string.IsNullOrEmpty(xmlNode5.Attributes["dBoxPowerSingle"].Value))
									{
										lineSettingIn.dBoxPowerSingle = double.Parse(xmlNode5.Attributes["dBoxPowerSingle"].Value);
									}
									else
									{
										lineSettingIn.dBoxPowerSingle = 0.0;
									}
									if (!string.IsNullOrEmpty(xmlNode5.Attributes["dBoxPowerMulti"].Value))
									{
										lineSettingIn.dBoxPowerMulti = double.Parse(xmlNode5.Attributes["dBoxPowerMulti"].Value);
									}
									else
									{
										lineSettingIn.dBoxPowerMulti = 0.0;
									}
									lineSettingIn.strKGL = xmlNode5.Attributes["strKGL"].Value;
									lineSettingIn.strBreaker = xmlNode5.Attributes["strBreaker"].Value;
									lineSettingIn.strDoubleSwich = xmlNode5.Attributes["strDoubleSwich"].Value;
									list2.Add(lineSettingIn);
								}
								if (list2.Count > 0)
								{
									list.Add(list2);
								}
							}
						}
					}
				}
			}
			return list;
		}

		public static List<List<LineSettingOut>> GetLineSettingOutInfo(string dir = null)
		{
			List<List<LineSettingOut>> list = new List<List<LineSettingOut>>();
			XmlNode xmlNode = GetXmlData.GetXmlNode(dir);
			for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
			{
				XmlNode xmlNode2 = xmlNode.ChildNodes[i];
				if (xmlNode2.Name == "UserControlData1")
				{
					for (int j = 0; j < xmlNode2.ChildNodes.Count; j++)
					{
						XmlNode xmlNode3 = xmlNode2.ChildNodes[j];
						if (xmlNode3.Name == "LineSettingOut")
						{
							foreach (object obj in xmlNode3.ChildNodes)
							{
								XmlNode xmlNode4 = (XmlNode)obj;
								List<LineSettingOut> list2 = new List<LineSettingOut>();
								foreach (object obj2 in xmlNode4.ChildNodes)
								{
									XmlNode xmlNode5 = (XmlNode)obj2;
									list2.Add(new LineSettingOut
									{
										dPowerRating = double.Parse(xmlNode5.Attributes["dPowerRating"].Value),
										strCps = xmlNode5.Attributes["strCps"].Value,
										strBreaker = xmlNode5.Attributes["strBreaker"].Value,
										strContactor = xmlNode5.Attributes["strContactor"].Value,
										strHotRelay = xmlNode5.Attributes["strHotRelay"].Value,
										strOutLine = xmlNode5.Attributes["strOutLine"].Value,
										dPipeDiameter = double.Parse(xmlNode5.Attributes["dPipeDiameter"].Value),
										strPerfunctoryWay = xmlNode5.Attributes["strPerfunctoryWay"].Value
									});
								}
								if (list2.Count > 0)
								{
									list.Add(list2);
								}
							}
						}
					}
				}
			}
			return list;
		}

		public static List<WiringInstructions> GetWiringInstructionsInfo(string dir = null)
		{
			List<WiringInstructions> list = new List<WiringInstructions>();
			XmlNode xmlNode = GetXmlData.GetXmlNode(dir);
			for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
			{
				XmlNode xmlNode2 = xmlNode.ChildNodes[i];
				if (xmlNode2.Name == "UserControlData1")
				{
					for (int j = 0; j < xmlNode2.ChildNodes.Count; j++)
					{
						XmlNode xmlNode3 = xmlNode2.ChildNodes[j];
						if (xmlNode3.Name == "WiringInstructions")
						{
							foreach (object obj in xmlNode3.ChildNodes)
							{
								XmlNode xmlNode4 = (XmlNode)obj;
								WiringInstructions wiringInstructions = new WiringInstructions();
								wiringInstructions.strTypeName = xmlNode4.Attributes["strTypeName"].Value;
								wiringInstructions.strSurge = xmlNode4.Attributes["strSurge"].Value;
								wiringInstructions.strCircuitScheme = xmlNode4.Attributes["strCircuitScheme"].Value;
								wiringInstructions.strRemarks = xmlNode4.Attributes["strRemarks"].Value;
								List<string> list2 = new List<string>();
								foreach (object obj2 in xmlNode4.ChildNodes)
								{
									XmlNode xmlNode5 = (XmlNode)obj2;
									list2.Add(xmlNode5.Attributes["lstWiringInstructions"].Value);
								}
								wiringInstructions.lstWiringInstructions = list2;
								list.Add(wiringInstructions);
							}
						}
					}
				}
			}
			return list;
		}

		public static Dictionary<string, List<string>> GetLstLstSetInfo2(string dir = null)
		{
			Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();
			XmlNode xmlNode = GetXmlData.GetXmlNode(dir);
			for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
			{
				XmlNode xmlNode2 = xmlNode.ChildNodes[i];
				if (xmlNode2.Name == "UserControlData2")
				{
					for (int j = 0; j < xmlNode2.ChildNodes.Count; j++)
					{
						XmlNode xmlNode3 = xmlNode2.ChildNodes[j];
						if (xmlNode3.Name == "BoxSize" || xmlNode3.Name == "LineType" || xmlNode3.Name == "SpoolType")
						{
							List<string> list = new List<string>();
							foreach (object obj in xmlNode3.ChildNodes)
							{
								XmlNode xmlNode4 = (XmlNode)obj;
								list.Add(xmlNode4.Attributes["Attribute"].Value);
							}
							dictionary.Add(xmlNode3.Name, list);
						}
					}
				}
			}
			return dictionary;
		}

		public static List<List<LineSettingInHouse>> GetLineSettingInHouseInfo(string dir = null)
		{
			List<List<LineSettingInHouse>> list = new List<List<LineSettingInHouse>>();
			XmlNode xmlNode = GetXmlData.GetXmlNode(dir);
			for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
			{
				XmlNode xmlNode2 = xmlNode.ChildNodes[i];
				if (xmlNode2.Name == "UserControlData2")
				{
					for (int j = 0; j < xmlNode2.ChildNodes.Count; j++)
					{
						XmlNode xmlNode3 = xmlNode2.ChildNodes[j];
						if (xmlNode3.Name == "LineSettingInHouse")
						{
							foreach (object obj in xmlNode3.ChildNodes)
							{
								XmlNode xmlNode4 = (XmlNode)obj;
								List<LineSettingInHouse> list2 = new List<LineSettingInHouse>();
								foreach (object obj2 in xmlNode4.ChildNodes)
								{
									XmlNode xmlNode5 = (XmlNode)obj2;
									list2.Add(new LineSettingInHouse
									{
										dBoxPower = double.Parse(xmlNode5.Attributes["dBoxPower"].Value),
										strMonophase = xmlNode5.Attributes["strMonophase"].Value,
										strBreaker = xmlNode5.Attributes["strBreaker"].Value,
										strTutamen = xmlNode5.Attributes["strTutamen"].Value
									});
								}
								if (list2.Count > 0)
								{
									list.Add(list2);
								}
							}
						}
					}
				}
			}
			return list;
		}

		public static List<List<LineSettingOutHouse>> GetLineSettingOutHouseInfo(string dir = null)
		{
			List<List<LineSettingOutHouse>> list = new List<List<LineSettingOutHouse>>();
			XmlNode xmlNode = GetXmlData.GetXmlNode(dir);
			for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
			{
				XmlNode xmlNode2 = xmlNode.ChildNodes[i];
				if (xmlNode2.Name == "UserControlData2")
				{
					for (int j = 0; j < xmlNode2.ChildNodes.Count; j++)
					{
						XmlNode xmlNode3 = xmlNode2.ChildNodes[j];
						if (xmlNode3.Name == "LineSettingOutHouse")
						{
							foreach (object obj in xmlNode3.ChildNodes)
							{
								XmlNode xmlNode4 = (XmlNode)obj;
								List<LineSettingOutHouse> list2 = new List<LineSettingOutHouse>();
								foreach (object obj2 in xmlNode4.ChildNodes)
								{
									XmlNode xmlNode5 = (XmlNode)obj2;
									list2.Add(new LineSettingOutHouse
									{
										strLoopName = xmlNode5.Attributes["strLoopName"].Value,
										strBreaker = xmlNode5.Attributes["strBreaker"].Value,
										strLoopNum = xmlNode5.Attributes["strLoopNum"].Value,
                                        //strLoopNum = xmlNode5.Attributes["strLoopNum"].Value,
										strLineSectionalArea = xmlNode5.Attributes["strLineSectionalArea"].Value,
										dPipeDiameter = double.Parse(xmlNode5.Attributes["dPipeDiameter"].Value),
										strPerfunctoryWay = xmlNode5.Attributes["strPerfunctoryWay"].Value,
										strReadFamilyName = xmlNode5.Attributes["strReadFamilyName"].Value
									});
								}
								if (list2.Count > 0)
								{
									list.Add(list2);
								}
							}
						}
					}
				}
			}
			return list;
		}

		public static void WriteNodeData(string strNodeName, string strChildNodeName, List<string> lst)
		{
			GetXmlData.GetXmlNode(null);
			string xpath = "Boot/" + strNodeName;
			string xpath2 = "Boot/" + strNodeName + "/" + strChildNodeName;
			XmlNode xmlNode = GetXmlData.sxmlDoc.SelectSingleNode(xpath);
			XmlNode xmlNode2 = GetXmlData.sxmlDoc.SelectSingleNode(xpath2);
			xmlNode.RemoveChild(xmlNode2);
			GetXmlData.sxmlDoc.Save(GetXmlData.strDirXml);
			XmlElement xmlElement = GetXmlData.sxmlDoc.CreateElement(strChildNodeName);
			xmlElement.SetAttribute("Attribute", GetXmlData.GetName(strChildNodeName));
			xmlNode.AppendChild(xmlElement);
			GetXmlData.sxmlDoc.Save(GetXmlData.strDirXml);
			xmlNode2 = GetXmlData.sxmlDoc.SelectSingleNode(xpath2);
			for (int i = 0; i < lst.Count; i++)
			{
				XmlElement xmlElement2 = GetXmlData.sxmlDoc.CreateElement("Type");
				xmlElement2.SetAttribute("Id", (i + 1).ToString());
				xmlElement2.SetAttribute("Attribute", lst[i]);
				xmlNode2.AppendChild(xmlElement2);
			}
			GetXmlData.sxmlDoc.Save(GetXmlData.strDirXml);
		}

		public static void WriteNameSet(List<string> lstName, List<string> lstTypeName)
		{
			GetXmlData.GetXmlNode(null);
			string xpath = "Boot/UserControlData1/NameSet";
			string xpath2 = "Boot/UserControlData1";
			XmlNode xmlNode = GetXmlData.sxmlDoc.SelectSingleNode(xpath2);
			XmlNode xmlNode2 = GetXmlData.sxmlDoc.SelectSingleNode(xpath);
			xmlNode.RemoveChild(xmlNode2);
			GetXmlData.sxmlDoc.Save(GetXmlData.strDirXml);
			XmlElement xmlElement = GetXmlData.sxmlDoc.CreateElement("NameSet");
			xmlElement.SetAttribute("Attribute", "名称设置");
			xmlNode.AppendChild(xmlElement);
			GetXmlData.sxmlDoc.Save(GetXmlData.strDirXml);
			xmlNode2 = GetXmlData.sxmlDoc.SelectSingleNode(xpath);
			for (int i = 0; i < lstName.Count; i++)
			{
				XmlElement xmlElement2 = GetXmlData.sxmlDoc.CreateElement("Type");
				xmlElement2.SetAttribute("Id", (i + 1).ToString());
				xmlElement2.SetAttribute("Name", lstName[i]);
				xmlElement2.SetAttribute("Attribute", lstTypeName[i]);
				xmlNode2.AppendChild(xmlElement2);
				GetXmlData.sxmlDoc.Save(GetXmlData.strDirXml);
			}
			GetXmlData.sxmlDoc.Save(GetXmlData.strDirXml);
		}

		private static string GetName(string name)
		{
			if (name.Equals("FanBoxSize"))
			{
				return "风机箱体尺寸";
			}
			if (name.Equals("PumpBoxSize"))
			{
				return "潜污泵箱体尺寸";
			}
			if (name.Equals("FireFightingLineType"))
			{
				return "消防导线类型";
			}
			if (name.Equals("NormalLineType"))
			{
				return "普通导线类型";
			}
			if (name.Equals("SpoolType"))
			{
				return "潜污泵箱体尺寸";
			}
			if (name.Equals("线管类型"))
			{
				return "潜污泵箱体尺寸";
			}
			if (name.Equals("BoxSize"))
			{
				return "住户配电箱箱体尺寸";
			}
			if (name.Equals("LineType"))
			{
				return "住户配电箱导线类型";
			}
			return "";
		}

		public static void WriteXml(string dir, List<List<LineSettingIn>> lstIineIn, List<List<LineSettingOut>> lstlineOut, List<List<LineSettingInHouse>> lstHouseIn, List<List<LineSettingOutHouse>> lstHouseOut, bool bl = false)
		{
			XmlDocument xmlDocument = new XmlDocument();
			XmlElement xmlElement = null;
			XmlElement xmlElement2 = null;
			if (!bl)
			{
				XmlDeclaration newChild = xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", null);
				xmlDocument.AppendChild(newChild);
				XmlElement xmlElement3 = xmlDocument.CreateElement("Boot");
				xmlDocument.AppendChild(xmlElement3);
				xmlElement = xmlDocument.CreateElement("UserControlData1");
				xmlElement3.AppendChild(xmlElement);
				xmlElement2 = xmlDocument.CreateElement("UserControlData2");
				xmlElement3.AppendChild(xmlElement2);
			}
			if (bl)
			{
				GetXmlData.GetXmlNode(null);
				xmlDocument = GetXmlData.sxmlDoc;
				string xpath = "Boot/UserControlData1";
				string xpath2 = "Boot/UserControlData2";
				xmlElement = (XmlElement)xmlDocument.SelectSingleNode(xpath);
				xmlElement2 = (XmlElement)xmlDocument.SelectSingleNode(xpath2);
			}
			int num = 1;
			if (lstIineIn.Count > 0)
			{
				XmlElement xmlElement4 = xmlDocument.CreateElement("LineSettingIn");
				xmlElement4.SetAttribute("Attribute", "进线设置");
				if (bl)
				{
					string xpath3 = "Boot/UserControlData1/LineSettingIn";
					XmlNode oldChild = xmlDocument.SelectSingleNode(xpath3);
					xmlElement.RemoveChild(oldChild);
				}
				xmlElement.AppendChild(xmlElement4);
				foreach (List<LineSettingIn> list in lstIineIn)
				{
					XmlElement xmlElement5 = xmlDocument.CreateElement("Type");
					xmlElement5.SetAttribute("Case", num.ToString());
					xmlElement5.SetAttribute("Attribute", "方案" + num.ToString());
					xmlElement4.AppendChild(xmlElement5);
					for (int i = 0; i < list.Count; i++)
					{
						XmlElement xmlElement6 = xmlDocument.CreateElement("Type");
						xmlElement6.SetAttribute("Id", (i + 1).ToString());
						xmlElement6.SetAttribute("dBoxPowerSingle", list[i].dBoxPowerSingle.ToString());
						xmlElement6.SetAttribute("dBoxPowerMulti", list[i].dBoxPowerMulti.ToString());
						xmlElement6.SetAttribute("strKGL", list[i].strKGL);
						xmlElement6.SetAttribute("strBreaker", list[i].strBreaker);
						xmlElement6.SetAttribute("strDoubleSwich", list[i].strDoubleSwich);
						xmlElement5.AppendChild(xmlElement6);
					}
					num++;
				}
			}
			num = 1;
			if (lstlineOut.Count > 0)
			{
				XmlElement xmlElement7 = xmlDocument.CreateElement("LineSettingOut");
				xmlElement7.SetAttribute("Attribute", "出线设置");
				if (bl)
				{
					string xpath4 = "Boot/UserControlData1/LineSettingOut";
					XmlNode oldChild2 = xmlDocument.SelectSingleNode(xpath4);
					xmlElement.RemoveChild(oldChild2);
				}
				xmlElement.AppendChild(xmlElement7);
				foreach (List<LineSettingOut> list2 in lstlineOut)
				{
					XmlElement xmlElement8 = xmlDocument.CreateElement("Type");
					xmlElement8.SetAttribute("Case", num.ToString());
					xmlElement8.SetAttribute("Attribute", "方案" + num.ToString());
					xmlElement7.AppendChild(xmlElement8);
					for (int j = 0; j < list2.Count; j++)
					{
						XmlElement xmlElement9 = xmlDocument.CreateElement("Type");
						xmlElement9.SetAttribute("Id", (j + 1).ToString());
						xmlElement9.SetAttribute("dPowerRating", list2[j].dPowerRating.ToString());
						xmlElement9.SetAttribute("strCps", list2[j].strCps);
						xmlElement9.SetAttribute("strBreaker", list2[j].strBreaker);
						xmlElement9.SetAttribute("strContactor", list2[j].strContactor);
						xmlElement9.SetAttribute("strHotRelay", list2[j].strHotRelay);
						xmlElement9.SetAttribute("strOutLine", list2[j].strOutLine);
						xmlElement9.SetAttribute("dPipeDiameter", list2[j].dPipeDiameter.ToString());
						xmlElement9.SetAttribute("strPerfunctoryWay", list2[j].strPerfunctoryWay);
						xmlElement8.AppendChild(xmlElement9);
					}
					num++;
				}
			}
			num = 1;
			if (lstHouseIn.Count > 0)
			{
				XmlElement xmlElement10 = xmlDocument.CreateElement("LineSettingInHouse");
				xmlElement10.SetAttribute("Attribute", "进线设置");
				if (bl)
				{
					string xpath5 = "Boot/UserControlData2/LineSettingInHouse";
					XmlNode oldChild3 = xmlDocument.SelectSingleNode(xpath5);
					xmlElement2.RemoveChild(oldChild3);
				}
				xmlElement2.AppendChild(xmlElement10);
				foreach (List<LineSettingInHouse> list3 in lstHouseIn)
				{
					XmlElement xmlElement11 = xmlDocument.CreateElement("Type");
					xmlElement11.SetAttribute("Case", num.ToString());
					xmlElement11.SetAttribute("Attribute", "方案" + num.ToString());
					xmlElement10.AppendChild(xmlElement11);
					for (int k = 0; k < list3.Count; k++)
					{
						XmlElement xmlElement12 = xmlDocument.CreateElement("Type");
						xmlElement12.SetAttribute("Id", (k + 1).ToString());
						xmlElement12.SetAttribute("dBoxPower", list3[k].dBoxPower.ToString());
						xmlElement12.SetAttribute("strMonophase", list3[k].strMonophase);
						xmlElement12.SetAttribute("strBreaker", list3[k].strBreaker);
						xmlElement12.SetAttribute("strTutamen", list3[k].strTutamen);
						xmlElement11.AppendChild(xmlElement12);
					}
					num++;
				}
			}
			num = 1;
			if (lstHouseOut.Count > 0)
			{
				XmlElement xmlElement13 = xmlDocument.CreateElement("LineSettingOutHouse");
				xmlElement13.SetAttribute("Attribute", "出线设置");
				if (bl)
				{
					string xpath6 = "Boot/UserControlData2/LineSettingOutHouse";
					XmlNode oldChild4 = xmlDocument.SelectSingleNode(xpath6);
					xmlElement2.RemoveChild(oldChild4);
				}
				xmlElement2.AppendChild(xmlElement13);
				foreach (List<LineSettingOutHouse> list4 in lstHouseOut)
				{
					XmlElement xmlElement14 = xmlDocument.CreateElement("Type");
					xmlElement14.SetAttribute("Case", num.ToString());
					xmlElement14.SetAttribute("Attribute", "方案" + num.ToString());
					xmlElement13.AppendChild(xmlElement14);
					for (int l = 0; l < list4.Count; l++)
					{
						XmlElement xmlElement15 = xmlDocument.CreateElement("Type");
						xmlElement15.SetAttribute("Id", (l + 1).ToString());
						xmlElement15.SetAttribute("strLoopName", list4[l].strLoopName);
						xmlElement15.SetAttribute("strBreaker", list4[l].strBreaker);
						xmlElement15.SetAttribute("strLoopNum", list4[l].strLoopNum);
						xmlElement15.SetAttribute("strLineSectionalArea", list4[l].strLineSectionalArea);
						xmlElement15.SetAttribute("dPipeDiameter", list4[l].dPipeDiameter.ToString());
						xmlElement15.SetAttribute("strPerfunctoryWay", list4[l].strPerfunctoryWay);
						xmlElement15.SetAttribute("strReadFamilyName", list4[l].strReadFamilyName);
						xmlElement14.AppendChild(xmlElement15);
					}
					num++;
				}
			}
			xmlDocument.Save(dir);
		}

		public static void WriteXml(string dir, List<WiringInstructions> lstWire, bool bl = false)
		{
			XmlDocument xmlDocument = new XmlDocument();
			XmlElement xmlElement = null;
			if (!bl)
			{
				XmlDeclaration newChild = xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", null);
				xmlDocument.AppendChild(newChild);
				XmlElement xmlElement2 = xmlDocument.CreateElement("Boot");
				xmlDocument.AppendChild(xmlElement2);
				xmlElement = xmlDocument.CreateElement("UserControlData1");
				xmlElement2.AppendChild(xmlElement);
			}
			if (bl)
			{
				GetXmlData.GetXmlNode(null);
				xmlDocument = GetXmlData.sxmlDoc;
				string xpath = "Boot/UserControlData1";
				xmlElement = (XmlElement)xmlDocument.SelectSingleNode(xpath);
			}
			int num = 1;
			if (lstWire.Count > 0)
			{
				XmlElement xmlElement3 = xmlDocument.CreateElement("WiringInstructions");
				xmlElement3.SetAttribute("Attribute", "接线说明");
				if (bl)
				{
					string xpath2 = "Boot/UserControlData1/WiringInstructions";
					XmlNode oldChild = xmlDocument.SelectSingleNode(xpath2);
					xmlElement.RemoveChild(oldChild);
				}
				xmlElement.AppendChild(xmlElement3);
				foreach (WiringInstructions wiringInstructions in lstWire)
				{
					XmlElement xmlElement4 = xmlDocument.CreateElement("Type");
					xmlElement4.SetAttribute("Id", num.ToString());
					xmlElement4.SetAttribute("strTypeName", wiringInstructions.strTypeName);
					xmlElement4.SetAttribute("strSurge", wiringInstructions.strSurge);
					xmlElement4.SetAttribute("strCircuitScheme", wiringInstructions.strCircuitScheme);
					xmlElement4.SetAttribute("strRemarks", wiringInstructions.strRemarks);
					xmlElement3.AppendChild(xmlElement4);
					for (int i = 0; i < wiringInstructions.lstWiringInstructions.Count; i++)
					{
						XmlElement xmlElement5 = xmlDocument.CreateElement("Case");
						xmlElement5.SetAttribute("lstWiringInstructions", wiringInstructions.lstWiringInstructions[i]);
						xmlElement4.AppendChild(xmlElement5);
					}
					num++;
				}
			}
			xmlDocument.Save(dir);
		}

		public static UserControlData1 GetUserData(string TypeName)
		{
			UserControlData1 userControlData = new UserControlData1();
			userControlData.strType = TypeName;
			XmlNode xmlNode = GetXmlData.GetXmlNode(null);
			for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
			{
				XmlNode xmlNode2 = xmlNode.ChildNodes[i];
				if (xmlNode2.Name == "HYSystemGrapSetHistory")
				{
					for (int j = 0; j < xmlNode2.ChildNodes.Count; j++)
					{
						XmlNode xmlNode3 = xmlNode2.ChildNodes[j];
						if (xmlNode3.Attributes["Attribute"].Value.Equals(TypeName))
						{
							string value = xmlNode3.Attributes["blBreaker"].Value;
							string value2 = xmlNode3.Attributes["blSurge"].Value;
							string value3 = xmlNode3.Attributes["blSwichTwo"].Value;
							string value4 = xmlNode3.Attributes["kx"].Value;
							string value5 = xmlNode3.Attributes["cosvo"].Value;
							string value6 = xmlNode3.Attributes["blHeng"].Value;
							string value7 = xmlNode3.Attributes["strBoxSize"].Value;
							string value8 = xmlNode3.Attributes["blBreakerOut"].Value;
							string value9 = xmlNode3.Attributes["strLineType"].Value;
							string value10 = xmlNode3.Attributes["strSpoolType"].Value;
							string value11 = xmlNode3.Attributes["InCase"].Value;
							string value12 = xmlNode3.Attributes["OutCase"].Value;
							userControlData.blBreaker = false;
							if (value.Equals("0"))
							{
								userControlData.blBreaker = true;
							}
							userControlData.blSurge = false;
							if (value2.Equals("0"))
							{
								userControlData.blSurge = true;
							}
							userControlData.blSwichTwo = false;
							if (value3.Equals("0"))
							{
								userControlData.blSwichTwo = true;
							}
							userControlData.dKx = double.Parse(value4);
							userControlData.dCos = double.Parse(value5);
							userControlData.blHeng = false;
							if (value6.Equals("0"))
							{
								userControlData.blHeng = true;
							}
							userControlData.strBoxSize = value7;
							userControlData.blBreakerOut = false;
							if (value8.Equals("0"))
							{
								userControlData.blBreakerOut = true;
							}
							userControlData.strLineType = value9;
							userControlData.strSpoolType = value10;
							userControlData.InCase = int.Parse(value11);
							userControlData.OutCase = int.Parse(value12);
							break;
						}
					}
				}
			}
			return userControlData;
		}

		public static UserControlData2 GetUserData()
		{
			UserControlData2 userControlData = new UserControlData2();
			XmlNode xmlNode = GetXmlData.GetXmlNode(null);
			for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
			{
				XmlNode xmlNode2 = xmlNode.ChildNodes[i];
				if (xmlNode2.Name == "HYSystemGrapSetHouseHistory")
				{
					for (int j = 0; j < xmlNode2.ChildNodes.Count; j++)
					{
						XmlNode xmlNode3 = xmlNode2.ChildNodes[j];
						if (xmlNode3.Attributes["Attribute"].Value.Equals("住户配电箱"))
						{
							string value = xmlNode3.Attributes["kx"].Value;
							string value2 = xmlNode3.Attributes["cosvo"].Value;
							string value3 = xmlNode3.Attributes["strBoxSize"].Value;
							string value4 = xmlNode3.Attributes["strLineType"].Value;
							string value5 = xmlNode3.Attributes["strSpoolType"].Value;
							string value6 = xmlNode3.Attributes["InCase"].Value;
							string value7 = xmlNode3.Attributes["OutCase"].Value;
							userControlData.dKx = double.Parse(value);
							userControlData.dCos = double.Parse(value2);
							userControlData.strBoxSize = value3;
							userControlData.strLineType = value4;
							userControlData.strSpoolType = value5;
							userControlData.InCase = int.Parse(value6);
							userControlData.OutCase = int.Parse(value7);
							break;
						}
					}
				}
			}
			return userControlData;
		}

		public static void UpdateUserData(UserControlData1 userData, string TypeName)
		{
			XmlDocument xmlDocument = new XmlDocument();
			string filename = Path.Combine(Product.WorkingLocation, "SystemGraphSet.xml");
			xmlDocument.Load(filename);
			string str;
			if (TypeName.Equals("普通风机"))
			{
				str = "Type2";
			}
			else if (TypeName.Equals("消防潜污泵"))
			{
				str = "Type3";
			}
			else if (TypeName.Equals("普通潜污泵"))
			{
				str = "Type4";
			}
			else
			{
				str = "Type1";
			}
			XmlElement xmlElement = (XmlElement)xmlDocument.SelectSingleNode("Boot/HYSystemGrapSetHistory/" + str);
			xmlElement.SetAttribute("blBreaker", userData.blBreaker ? "0" : "1");
			xmlElement.SetAttribute("blSurge", userData.blSurge ? "0" : "1");
			xmlElement.SetAttribute("blSwichTwo", userData.blSwichTwo ? "0" : "1");
			xmlElement.SetAttribute("kx", userData.dKx.ToString());
			xmlElement.SetAttribute("cosvo", userData.dCos.ToString());
			xmlElement.SetAttribute("blHeng", userData.blHeng ? "0" : "1");
			xmlElement.SetAttribute("strBoxSize", userData.strBoxSize);
			xmlElement.SetAttribute("blBreakerOut", userData.blBreakerOut ? "0" : "1");
			xmlElement.SetAttribute("strLineType", userData.strLineType);
			xmlElement.SetAttribute("strSpoolType", userData.strSpoolType);
			xmlDocument.Save(filename);
		}

		public static void UpdateUserData(int inValue, int outValue, bool bl, string type)
		{
			XmlDocument xmlDocument = new XmlDocument();
			string filename = Path.Combine(Product.WorkingLocation, "SystemGraphSet.xml");
			xmlDocument.Load(filename);
			XmlElement xmlElement = (XmlElement)xmlDocument.SelectSingleNode("Boot/HYSystemGrapSetHistory/Type1");
			XmlElement xmlElement2 = (XmlElement)xmlDocument.SelectSingleNode("Boot/HYSystemGrapSetHistory/Type2");
			XmlElement xmlElement3 = (XmlElement)xmlDocument.SelectSingleNode("Boot/HYSystemGrapSetHistory/Type3");
			XmlElement xmlElement4 = (XmlElement)xmlDocument.SelectSingleNode("Boot/HYSystemGrapSetHistory/Type4");
			if (bl)
			{
				xmlElement.SetAttribute("InCase", inValue.ToString());
				xmlElement2.SetAttribute("InCase", inValue.ToString());
				xmlElement3.SetAttribute("InCase", inValue.ToString());
				xmlElement4.SetAttribute("InCase", inValue.ToString());
			}
			else
			{
				xmlElement.SetAttribute("OutCase", outValue.ToString());
				xmlElement2.SetAttribute("OutCase", outValue.ToString());
				xmlElement3.SetAttribute("OutCase", outValue.ToString());
				xmlElement4.SetAttribute("OutCase", outValue.ToString());
			}
			xmlDocument.Save(filename);
		}

		public static void UpdateUserData(UserControlData2 userData, string TypeName)
		{
			XmlDocument xmlDocument = new XmlDocument();
			string filename = Path.Combine(Product.WorkingLocation, "SystemGraphSet.xml");
			xmlDocument.Load(filename);
			string str = "Type1";
			XmlElement xmlElement = (XmlElement)xmlDocument.SelectSingleNode("Boot/HYSystemGrapSetHouseHistory/" + str);
			xmlElement.SetAttribute("kx", userData.dKx.ToString());
			xmlElement.SetAttribute("cosvo", userData.dCos.ToString());
			xmlElement.SetAttribute("strBoxSize", userData.strBoxSize);
			xmlElement.SetAttribute("strLineType", userData.strLineType);
			xmlElement.SetAttribute("strSpoolType", userData.strSpoolType);
			xmlElement.SetAttribute("InCase", userData.InCase.ToString());
			xmlElement.SetAttribute("OutCase", userData.OutCase.ToString());
			xmlDocument.Save(filename);
		}

		private static XmlDocument sxmlDoc = null;

		private static string strDirXml = "";
	}
}
